package leetcode.array;

import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

/**
 * leetCode 80
 * 删除排序数组中的重复项 II
 * 思路：我们使用快慢指针来记录遍历的坐标，与前两位比较

 */
public class Array80 {

    public static void main(String []args){
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        List<Integer> input = Arrays.stream(str.split(",")).map(i -> { return Integer.parseInt(i); }).collect(Collectors.toList());
        System.out.println(Arrays.toString(input.toArray()));
        Integer [] nums = input.toArray(new Integer[input.size()]);
        new Array80().removeDuplicates(nums);
    }
    public int removeDuplicates(Integer[] nums) {
        int len = nums.length;
        if (len < 3) return len;
        int pos = 2;
        for (int i = 2; i < len ; i ++) {
            if(nums[i] != nums[pos - 2]){
                nums[pos ++] = nums[i];
            }
        }
        return pos;
    }
}
